package lyx.tank.stages
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.KeyboardEvent;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.ui.Keyboard;
	
	import lyx.game.GameEngine;
	import lyx.game.stage.GameStage;
	import lyx.utils.log.Logger;
	
	public class StartMenuStage extends GameStage
	{
		private var _view:Bitmap;
		
		override protected function initGameStageView():void
		{
			_view = _view = new Bitmap(new BitmapData(640,480,true,0));
			addChild(_view);
			initStageBackground();
			initGameTitle();
		}
		
		override protected function initGameStageEvent():void
		{
			stage.addEventListener(KeyboardEvent.KEY_DOWN,keyBoardHandler);
		}
		
		override protected function destoryGameStageEvent():void
		{
			stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyBoardHandler);
		}
		
		private function initStageBackground():void
		{
			graphics.beginFill(0x868686);
			graphics.drawRect(0,0,640,480);
			graphics.endFill();
			_view.bitmapData.draw(this);
		}
		
		private function initGameTitle():void
		{
			var game_title:TextField = new TextField();
			game_title.autoSize = TextFieldAutoSize.LEFT;
			game_title.background = true;
			game_title.backgroundColor = 0x909090;
			game_title.text = "Cookie Game One";
			var text_format:TextFormat = new TextFormat();
			text_format.size = 36;
			game_title.setTextFormat(text_format);
			
			_view.bitmapData.draw(game_title,new Matrix(1,0,0,1,170,50));
		}
		
		private function keyBoardHandler(event:KeyboardEvent):void
		{
			if(event.keyCode==Keyboard.ENTER)
			{
				Logger.getInstance().debug("Start to play game!");
				GameEngine.getInstance().switchGameStage(LevelInStage,{'level_name':"1"});
			}
		}
	}
}